package com.yu.smsinterceptor;

import android.app.Application;
import android.util.Log;

import org.xutils.DbManager;
import org.xutils.db.table.TableEntity;
import org.xutils.x;

public class XUtilsApplication extends Application {

    private static final String DATABASE_NAME = "draw_number";

    private static DbManager.DaoConfig mDaoConfig;

    public static DbManager.DaoConfig getDaoConfig() {
        if (mDaoConfig == null) {
            mDaoConfig = new DbManager.DaoConfig()
                    .setDbName(DATABASE_NAME)
                    .setDbVersion(1)
                    //.setDbDir(null)//设置数据库.db文件存放的目录,默认为包名下databases目录下
                    .setDbOpenListener(new DbManager.DbOpenListener() {//设置数据库打开的监听
                        @Override
                        public void onDbOpened(DbManager db) {
                            //开启数据库支持多线程操作，提升性能，对写入加速提升巨大
                            db.getDatabase().enableWriteAheadLogging();
                        }
                    })
                    .setDbUpgradeListener(new DbManager.DbUpgradeListener() {//设置数据库更新的监听
                        @Override
                        public void onUpgrade(DbManager db, int oldVersion, int newVersion) {

                        }
                    })
                    .setTableCreateListener(new DbManager.TableCreateListener() {//设置表创建的监听
                        @Override
                        public void onTableCreated(DbManager db, TableEntity<?> table) {
                            Log.i("TAG", "创建表 " + table.getName());
                        }
                    });
        }

        return mDaoConfig;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        x.Ext.init(this);
        x.Ext.setDebug(false);
    }
}
